package com.hhq.Dao.Impl;

import com.hhq.Dao.JobDao;
import com.hhq.entity.Dept;
import com.hhq.entity.Job;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class JobDaoImpl implements JobDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public List<Job> getAllJob() {
        String sql = "select * from job";
        List<Job> list = jdbcTemplate.query(sql,new BeanPropertyRowMapper<Job>(Job.class));
        return list;
    }

    @Override
    public List<Job> findJobByName(String name) {
        String sql = "select * from job where name = ?";
        return jdbcTemplate.query(sql,new BeanPropertyRowMapper<>(Job.class), name);
    }

    @Override
    public int addJob(Job job) {
        String sql = "insert into job(name,remark ) value(?,?)";
        int num = jdbcTemplate.update(sql,new Object[]{
                job.getName(),
                job.getRemark()
        });
        return num;
    }

    @Override
    public int updateJob(Job job) {
        String sql = "update job set name=?,remark=? where name = ?";
        Object object = new Object[]{
                job.getName(),
                job.getRemark(),
                job.getName()
        };
       int num = jdbcTemplate.update(sql,object);
       return num;
    }

    @Override
    public void deleteJob(String name) {
        String sql = "delete from job where name=?";
        jdbcTemplate.update(sql,new Object[]{name});
    }


}
